import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { Language } from "../../../../../extend/language/Language";
import { CrossGuildWarRewardData } from "../data/CrossGuildWarRewardData";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PageItemRenderer } from "../../common/renderers/PageItemRenderer";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { CrossGuildWarRewardRender } from "../render/CrossGuildWarRewardRender";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { SecTimerView } from "../../common/SecTimerView";
type int = number;
//class CrossGuildWarSignUpSubWin
    
    export  class CrossGuildWarSignUpSubWin extends GSprite
    {
        constructor()
        {
            super();
            this._btnSignUp.configEventListener(flash.events.MouseEvent.CLICK, this.signUpReqHandler);
            this._btnEnter.configEventListener(flash.events.MouseEvent.CLICK, this.clickEnterHandler);
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            if (this._leftTime != null) 
            {
                this._leftTime.stop();
                this._leftTime.dispose(arg1);
                this._leftTime = null;
            }
            return;
        }

        /* internal  */signUpReqHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarSignUpReq));
            return;
        }

        /* internal  */clickEnterHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarPassToReq));
            return;
        }

        public set signUpEnabled(arg1: Boolean)
        {
            if (arg1) 
            {
                DisplayUtil.removeMe(this._btnEnter);
                this.addChild(this._btnSignUp);
            }
            else 
            {
                DisplayUtil.removeMe(this._btnSignUp);
                this.addChild(this._btnEnter);
            }
            return;
        }

        public updateCurHave(arg1: int): void
        {
            this._txtCurHave.htmlText = Language.getStringByParam(80539, arg1.toString());
            return;
        }

        public updateCurSignUpCount(arg1: int): void
        {
            this._txtSignUpCount.htmlText = Language.getStringByParam(80551, arg1.toString());
            return;
        }

        public updateLeftTime(arg1: int): void
        {
            if (arg1 <= 0) 
            {
                if (this._leftTime.running) 
                {
                    this._leftTime.stop();
                }
                this._leftTime.htmlText = Language.getString(80599);
            }
            else 
            {
                this._leftTime.setParse(Language.getString(80541));
                this._leftTime.setLeftTime(arg1);
            }
            this.signUpEnabled = arg1 > 0;
            return;
        }

        /* internal  */updateRewards(): void
        {
            var loc4=null;
            var loc1=Language.getString(80569).split(",");
            var loc2=[];
            var loc3=0;
            while (loc3 < loc1.length && loc3 < this.rewardNames.length) 
            {
                (loc4 = new CrossGuildWarRewardData()).rewardCode = int(loc1[loc3]);
                loc4.imgName = this.rewardNames[loc3];
                loc2.push(loc4);
                ++loc3;
            }
            this._rewardList.dataProvider = new DataProvider(loc2);
            this._rewardList.drawNow();
            return;
        }

        /* internal  */updateCanExchangeList(): void
        {
            var loc1=Language.getString(80560).split(",");
            var loc2=new DataProvider();
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc2.addItem(int(loc1[loc3]));
                ++loc3;
            }
            this._exchangeList.dataProvider = loc2;
            this._exchangeList.drawNow();
            return;
        }

        protected /* override */ configUI(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            super.configUI();
            ObjCreate.createFlowerBg(0, 0, 804, 128, this);
            ObjCreate.createBitmap(ImagesConst.CrossGuildWar_Flag, 44, 13, this);
            loc2 = GlobalStyle.textFormat1;
            loc2.leading = 6;
            loc1 = ObjCreate.createGTextField("", 113, 11, 660, 40, this, loc2);
            loc1.multiline = true;
            loc1.wordWrap = true;
            loc1.htmlText = Language.getString(80537);
            loc1 = ObjCreate.createGTextField("", 113, 56, 250, 20, this);
            loc1.htmlText = Language.getString(80538);
            this._txtCurHave = ObjCreate.createGTextField("", 473, 56, 220, 20, this);
            this._txtCurHave.htmlText = Language.getStringByParam(80539, 0);
            loc1 = ObjCreate.createGTextField("", 631, 56, 220, 20, this);
            loc1.htmlText = Language.getString(80540);
            loc1.addEventListener(flash.events.TextEvent.LINK, this.openGuildShopReqHandler);
            ObjCreate.createBg(200, 75, 440, 46, this, "RemainningTimeBg");
            this._exchangeList = ObjCreate.createTileList(246, 79, 500, 60, this);
            this._exchangeList.columnWidth = 36;
            this._exchangeList.setStyle("cellRenderer", PageItemRenderer);
            this._exchangeList.horizontalGap = 6;
            this.updateCanExchangeList();
            loc3 = new Object /* flash.display.Bitmap */();
            loc3.x = 0;
            loc3.y = 132;
            this.addChild(loc3);
            LoaderHelp.setBitmapdata(ImagesConst.CrossGuildWarBg2 + ".swf", loc3, 0, 0, 804, 173);
            this._btnSignUp = ObjCreate.createGLoadedButton(ResFileConst.CrossGuildWarSignUpBtn, 356, 168, 97, 50, this);
            this._btnEnter = ObjCreate.createGLoadedButton(ResFileConst.CrossGuildWarEnterBtn, 356, 168, 97, 50, this);
            this._txtSignUpCount = ObjCreate.createGTextField(Language.getStringByParam(80551, 0), 325, 244, 200, 20, this, null, true);
            this._txtsignUpList = ObjCreate.createGTextField(Language.getString(80542), 445, 244, 200, 20, this, null, true);
            this._txtsignUpList.addEventListener(flash.events.TextEvent.LINK, this.textLinkHandler);
            this._leftTime = ObjCreate.createSecTimeView(Language.getString(80541), 342, 264, 200, 20, this);
            this._leftTime.setLeftTime(1800);
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.timeOutHandler = this.signUpTimeOutHandler;
            ObjCreate.createBg(0, 309, 804, 163, this);
            ObjCreate.createBitmap(ImagesConst.CrossGuildWar_Rank, 277, 316, this);
            ObjCreate.createBitmap(ImagesConst.RechargeFlwBg, 218, 326, this);
            ObjCreate.createBg(260, 341, 280, 1, this, ImagesConst.SplitLine);
            var loc4;
            (loc4 = ObjCreate.createBitmap(ImagesConst.RechargeFlwBg, 588, 326, this)).rotationY = -180;
            this._rewardList = ObjCreate.createTileList(16, 348, 800, 120, this);
            this._rewardList.columnWidth = 120;
            this._rewardList.horizontalGap = 10;
            this._rewardList.setStyle("cellRenderer", CrossGuildWarRewardRender);
            this.updateRewards();
            return;
        }

        /* internal  */openGuildShopReqHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (Cache.instance.guild.myGuildInfo == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(41802));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenShop));
            return;
        }

        /* internal  */textLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarShowSignUpList));
            return;
        }

        /* internal  */signUpTimeOutHandler(): void
        {
            this.signUpEnabled = false;
            return;
        }

        /* internal */ /* const */rewardNames: Array<any>=["CrossGuildWar_Champion", "CrossGuildWar_Second", "CrossGuildWar_Top4", "CrossGuildWar_Top8", "CrossGuildWar_Top16", "CrossGuildWar_Top32"];

        /* internal */ /* var */_exchangeList: GTileList;

        /* internal */ /* var */_btnSignUp: GLoadedButton;

        /* internal */ /* var */_btnEnter: GLoadedButton;

        /* internal */ /* var */_txtSignUpCount: GTextFiled;

        /* internal */ /* var */_txtsignUpList: GTextFiled;

        /* internal */ /* var */_leftTime: SecTimerView;

        /* internal */ /* var */_txtCurHave: GTextFiled;

        /* internal */ /* var */_rewardList: GTileList;
    }
